<?php
/**
 * @author Sergey Dostovalov
 */
require_once 'MarcField.php';
require_once 'MarcConstants.php';
class MarcControlField extends MarcField {
    protected $data;
    /**
     * 
     * @param string $tag tag of field
     * @param string $data data of field
     * @param null $ind1 bc control field no have indicators
     * @param null $ind2 bc control field no have indicators
     */
    public function  __construct($tag, $data, $ind1 = null, $ind2 = null)
    {
        parent::__construct($tag);
        $this->data = $data;
    }
    public function  __destruct() {
       // $this->$data = null;
    }

    public function delete(){
        $this->__destruct();
    }
    /**
     *
     * @return string data of field
     */
    public function getData()
    {
        return $this->data;
    }
    /**
     *
     * @return bool
     */
    public function isEmpty()
    {
        return ($this->data) ? false : true;
    }
    /**
     *
     * @param string $toEncoding
     * @return string raw field data
     */
    public function toRaw($toEncoding = null){
        if ($toEncoding !== null){
            return mb_convert_encoding($this->data, $toEncoding,'UTF-8').MarcConstants::END_OF_FIELD;
        }
        return $this->data.MarcConstants::END_OF_FIELD;
    }
    /**
     *
     * @param string $data field data
     */
    public function setData($data)
    {
        $this->data = $data;
    }
    /**
     *
     * @return string formating string of field data
     */
    public function __toString()
    {
        return sprintf('%3s     %s', $this->tag, $this->data);
    }
}
?>
